package com.oa.controller;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.oa.entity.Dept;
import com.oa.service.DeptService;

@Controller
@RequestMapping("/dept")
public class DeptController {
	@Resource
	private DeptService deptService;

	@RequestMapping("/findAll")
	public String findAll(Map<String,Object> map) {
		map.put("deptList", deptService.findAll());
		map.put("dept", new Dept());
		return "dept-list";
	}
	@RequestMapping("/deleteDept/{id}")
	public String deleteDept(@PathVariable("id") int deptno){
		deptService.deleteDept(deptno);
		return "redirect:/dept/findAll";
	}
	@RequestMapping("/toSave")
	public String toSave(Map<String,Object> map){
		map.put("dept", new Dept());
		return "dept-save";
	}
	@RequestMapping("/saveDept")
	public String saveDept(Dept dept){
		deptService.saveDept(dept);
		return "redirect:/dept/findAll";
	}
	@RequestMapping("/toUpdate/{id}")
	public String toUpdate(@PathVariable("id") Integer deptno,Map<String,Object> map ){
		map.put("dept", deptService.getDept(deptno));
		map.put("deptList", deptService.findAll());
		return "dept-list";
	}
	@RequestMapping("/updateDept")
	public String updateDept(Dept dept){
		deptService.updateDept(dept);
		return "redirect:/dept/findAll";
	}
}
